// UVa10635 Prince and Princess
// 陈锋
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 256, MAXP = MAXN * MAXN;
typedef vector<int> VI;
int IDX[MAXP];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int T; cin >> T;
  for (int t = 1, n, a, p, q; cin >> n >> p >> q && n; t++) {
    ++p, ++q;
    fill_n(IDX, n * n + 2, 0);
    for (int i = 1; i <= p; i++) cin >> a, IDX[a] = i;
    VI D;
    for (int i = 0, b; i < q; i++) {
      cin >> b, b = IDX[b];
      if (b == 0) continue;
      VI::iterator it = lower_bound(D.begin(), D.end(), b);
      if (it == D.end()) D.push_back(b);
      else *it = b;
    }
    printf("Case %d: %llu\n", t, D.size());
  }
  return 0;
}
/*
算法分析请参考: 《入门经典训练指南-升级版》 1.4节 例题27
*/
// 26180630 10635 Prince and Princess Accepted  C++ 0.010 2021-03-12 09:03:43